<?php
class OneAction extends AdminAction {

	#列表
	function index() {

		$obj = M('Onepage');

		$count = $obj->count();

		import("@.ORG.Page");

		$page = new Page($count, 20);

		$show = $page->show();

		$list = $obj->order('id asc')->limit($page->firstRow . ',' . $page->listRows)->select();

		$this->assign('list', $list);

		$this->assign('page', $show);

		$this->display();

	}

	#添加
	function Add() {
		$this->display();
	}

	#保存
	function Save() {
		$obj = D('Onepage');
		if ($data = $obj->create()) {
			if ($obj->add($data)) {
				$state = 'SUCCESS';
	            $message = '添加成功';
	            $url = U('One/index');
			} else {
				$state = '添加失败';
			}
		} else {
			$state = $obj->getError();
		}
		echo $this->echo_json_str($state,$message,$url);
	}

	#编辑
	function Edit() {

		$id = (int) $_GET['id'];

		if (!isset ($id)) {
			$this->error('参数错误');
		}

		$obj = M('Onepage');

		$list = $obj->where("id=$id")->find();

		if (!$list) {
			$this->error('信息不存在');
		} else {
			$this->assign('list', $list);
			$this->display();
		}

	}

	#更新
	function Update() {

		$obj = D('Onepage');

		if ($data = $obj->create()) {

			if ($obj->save($data)) {
				$state = 'SUCCESS';
	            $message = '编辑成功';
	            $url = U('One/index');
			} else {
				$state = '编辑失败';
			}
		} else {
			$state = $obj->getError();
		}
		echo $this->echo_json_str($state,$message,$url);

	}

	#删除
	function Del() {

		$id=I('post.selectedids');
		$cityID = I('post.city');

		if($id==''){
			$state = "您没有选择任何信息！";
		}else{
			foreach ($id as $v) {
				$obj = M('Onepage');
				$where['id'] = $v;
				$obj->where($where)->delete();
			}
			$state = 'SUCCESS';
	        $message = '删除成功';
	        $url = U('One/index');
		}
		echo $this->echo_json_str($state,$message,$url);
	}

}
?>